﻿/*
 *    Copyright [2010] [Daniel Sawan]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package com.kikoulol.jarmory.extractor;

import java.io.File;

public abstract class ExtractorConfig
{
  private static long antiSpamTime = 2000; // If this value is < 10, it is
                                           // considered as seconds else it is
                                           // considered as milliseconds
  private static boolean cacheActive = true;
  private static String cacheFolder = "cache";
  private static boolean logEnabled = true;
  private static int maxTries = 5;

  /**
   * 
   */
  public final static void cleanCache()
  {
    File cache = new File(ExtractorConfig.getCacheFolder());
    for (File file : cache.listFiles())
    {
      file.delete();
    }
    cache.delete();
  }

  public final static long getAntiSpamTime()
  {
    return ExtractorConfig.antiSpamTime;
  }

  public final static String getCacheFolder()
  {
    return ExtractorConfig.cacheFolder;
  }

  public static int getMaxTries()
  {
    return maxTries;
  }

  public final static boolean isCacheActive()
  {
    return ExtractorConfig.cacheActive;
  }

  public final static boolean isLogEnabled()
  {
    return ExtractorConfig.logEnabled;
  }

  public final static void setAntiSpamTime(long antiSpamTime)
  {
    ExtractorConfig.antiSpamTime = antiSpamTime;
  }

  public final static void setCacheActive(boolean cacheActive)
  {
    ExtractorConfig.cacheActive = cacheActive;
  }

  public final static void setCacheFolder(String cacheFolder)
  {
    ExtractorConfig.cacheFolder = cacheFolder;
  }
  
  public final static void setLogEnabled(boolean logEnabled)
  {
    ExtractorConfig.logEnabled = logEnabled;
  }

  public final static void setMaxTries(int maxTries)
  {
    ExtractorConfig.maxTries = maxTries;
  }

  /**
   * Convenient method to wait the preconfigured time in Utils class
   */
  public final static void waitAntiSpamTime()
  {
    ExtractorConfig.waitSomeTime(ExtractorConfig.antiSpamTime);
  }

  /**
   * 
   * @param s
   *          If this value is < 10, it is considered as seconds else it is
   *          considered as milliseconds
   */
  @SuppressWarnings("static-access")
  public final static void waitSomeTime(long s)
  {
    try
    {
      if (s < 10)
      {
        Thread.currentThread().sleep(s * 1000);
      }
      else
      {
        Thread.currentThread().sleep(s);
      }
    }
    catch (InterruptedException e)
    {
      e.printStackTrace();
    }
  }
}
